package com.google.project.server.entity;


import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import javax.jdo.annotations.Element;
import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

import com.google.project.shared.ProjectTaskDTO;

@SuppressWarnings("serial")
@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class ProjectTask implements Serializable {

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String id;
	
	@Persistent
	private int taskId;
	@Persistent
	private int group;
	@Persistent
	private int parentId;
	@Persistent
	private int isMile;
	@Persistent
	private String taskName;
	@Persistent
	private Double amountOfWork;
	@Persistent
	private String unit;
	@Persistent
	private Double finishedWork;
	@Persistent
	private Long startDate;
	@Persistent
	private Long dueDate;
	@Persistent
	private Long finishDate;
	@Persistent
	private int status;
	@Persistent
	private String optAccountName;
	@Persistent
	private String optUserId;
	@Persistent
	private String subContructor;
	@Persistent
	private String description;
	@Persistent
	private String projectId;
	@Persistent
	private Double weight;
	@Persistent
	private String subTasks;
	@Persistent
	private String dependent;
	@Persistent
	private Project project;
	

	@Persistent(mappedBy = "projectTask")
	@Element(dependent = "true")
	private List<TaskConstrain> listOfConstrain = new ArrayList<TaskConstrain>();
	
	@Persistent(mappedBy = "projectTask")
	@Element(dependent = "true")
	private List<TaskRequire> listOfTaskRequire = new ArrayList<TaskRequire>();
	
	public String getId() {
		return id;
	}


	public String getOptUserId() {
		return optUserId;
	}


	public void setOptUserId(String optUserId) {
		this.optUserId = optUserId;
	}


	public String getDependent() {
		return dependent;
	}


	public void setDependent(String dependent) {
		this.dependent = dependent;
	}


	public List<TaskConstrain> getListOfConstrain() {
		return listOfConstrain;
	}


	public void setListOfConstrain(List<TaskConstrain> listOfConstrain) {
		this.listOfConstrain = listOfConstrain;
	}


	public String getSubTasks() {
		return subTasks;
	}

	public void setSubTasks(String subTasks) {
		this.subTasks = subTasks;
	}

	public int getTaskId() {
		return taskId;
	}

	public void setTaskId(int taskId) {
		this.taskId = taskId;
	}

	public int getGroup() {
		return group;
	}

	public void setGroup(int group) {
		this.group = group;
	}

	public int getParentId() {
		return parentId;
	}

	public void setParentId(int parentId) {
		this.parentId = parentId;
	}

	public int getIsMile() {
		return isMile;
	}

	public void setIsMile(int isMile) {
		this.isMile = isMile;
	}

	public Double getWeight() {
		return weight;
	}

	public void setWeight(Double weight) {
		this.weight = weight;
	}

	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getTaskName() {
		return taskName;
	}

	public void setTaskName(String taskName) {
		this.taskName = taskName;
	}

	public Double getAmountOfWork() {
		return amountOfWork;
	}

	public void setAmountOfWork(Double amountOfWork) {
		this.amountOfWork = amountOfWork;
	}

	public String getUnit() {
		return unit;
	}

	public void setUnit(String unit) {
		this.unit = unit;
	}

	public Double getFinishedWork() {
		return finishedWork;
	}

	public void setFinishedWork(Double finishedWork) {
		this.finishedWork = finishedWork;
	}

	public Long getStartDate() {
		return startDate;
	}

	public void setStartDate(Long startDate) {
		this.startDate = startDate;
	}

	public Long getDueDate() {
		return dueDate;
	}

	public void setDueDate(Long dueDate) {
		this.dueDate = dueDate;
	}

	public Long getFinishDate() {
		return finishDate;
	}

	public void setFinishDate(Long finishDate) {
		this.finishDate = finishDate;
	}

	public int getStatus() {
		return status;
	}

	public void setStatus(int status) {
		this.status = status;
	}

	public String getOptAccountName() {
		return optAccountName;
	}

	public void setOptAccountName(String optAccountName) {
		this.optAccountName = optAccountName;
	}

	public String getSubContructor() {
		return subContructor;
	}

	public void setSubContructor(String subContructor) {
		this.subContructor = subContructor;
	}

	public String getDescription() {
		return description;
	}

	public void setDescription(String description) {
		this.description = description;
	}


	public ProjectTask() {
		super();
	}

	public String getProjectId() {
		return projectId;
	}

	public void setProjectId(String projectId) {
		this.projectId = projectId;
	}
	
	public void updateFromDTO(ProjectTaskDTO data) {
		this.dependent=data.getDependent();
		this.subTasks = data.getSubTasks();
		this.group = data.getGroup();
		this.isMile = data.getIsMile();
		this.parentId = data.getParentId();
		this.taskName = data.getTaskName();
		this.amountOfWork = data.getAmountOfWork();
		this.unit = data.getUnit();
		this.finishedWork = data.getFinishedWork();
		this.startDate = data.getStartDate();
		this.dueDate = data.getDueDate();
		this.finishDate = data.getFinishDate();
		this.status = data.getStatus();
		this.optAccountName = data.getOptAccountName();
		this.subContructor = data.getSubContructor();
		this.description = data.getDescription();
	//	this.project = data.getProject();
		this.projectId=data.getProjectId();
		this.weight = data.getWeight();
		this.optUserId = data.getOptUserId();
		
		
		
	}
	
	public ProjectTask(ProjectTaskDTO data) {
		this.dependent= data.getDependent();
		this.subTasks = data.getSubTasks();
		this.taskId = data.getTaskId();
		this.group = data.getGroup();
		this.isMile = data.getIsMile();
		this.parentId = data.getParentId();
		this.taskName = data.getTaskName();
		this.amountOfWork = data.getAmountOfWork();
		this.unit = data.getUnit();
		this.finishedWork = data.getFinishedWork();
		this.startDate = data.getStartDate();
		this.dueDate = data.getDueDate();
		this.finishDate = data.getFinishDate();
		this.status = data.getStatus();
		this.optAccountName = data.getOptAccountName();
		this.subContructor = data.getSubContructor();
		this.description = data.getDescription();
		this.projectId=data.getProjectId();
		this.weight = data.getWeight();
		this.optUserId = data.getOptUserId();
	}

	public ProjectTaskDTO toDTO() {
		ProjectTaskDTO data = new ProjectTaskDTO();
		data.setDependent(dependent);
		data.setSubTasks(subTasks);
		data.setTaskId(taskId);
		data.setGroup(group);
		data.setIsMile(isMile);
		data.setParentId(parentId);
		data.setId(id);
		data.setTaskName(taskName);
		data.setAmountOfWork(amountOfWork); 
		data.setUnit(unit);
		data.setFinishedWork(finishedWork);
		data.setStartDate(startDate);
		data.setDueDate(dueDate);
		data.setFinishDate(finishDate);
		data.setStatus(status);
		data.setOptAccountName(optAccountName);
		data.setSubContructor(subContructor);
		data.setDescription(description);
		
		data.setProjectId(projectId);
		data.setWeight( this.weight);
		data.setOptUserId(optUserId);
		if(project!=null)
		{
		data.setProject(project.toDTO());
		}
		return data;
	}


	public List<TaskRequire> getListOfTaskRequire() {
		return listOfTaskRequire;
	}


	public void setListOfTaskRequire(List<TaskRequire> listOfTaskRequire) {
		this.listOfTaskRequire = listOfTaskRequire;
	}
	
}
